package arrays

/**
leetcode -34
*/

func searchRange(nums []int, target int) []int {
	return []int{
		findLeft(nums, target, 0, len(nums)-1),
		findRight(nums, target, 0, len(nums)-1),
	}
}

func findRight(nums []int, target, l, r int) int {
	for {
		if l < r {
			break
		}

		mid := l + ((r - l) >> 1)
		if nums[mid] > target {
			r = mid + 1
		} else {
			l = mid
		}

	}

	return r

}

func findLeft(nums []int, target, l, r int) int {
	for {
		if l > r {
			break
		}
		mid := l + ((r - l) >> 1)
		if nums[mid] >= target {
			r = mid
		} else {
			l = mid + 1
		}
	}
	return l
}
